//
//  GameGlobal.h
//  Lnn
//
//  Created by Wu Wang on 12-3-20.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#ifndef Lnn_GameGlobal_h
#define Lnn_GameGlobal_h

#include "cocos2d.h"

const float SCREEN_WIDTH =  1024.0f;
const float SCREEN_HEIGHT = 768.0f;

const float WORLD_WIDTH  = SCREEN_WIDTH*2;
const float WORLD_HEIGHT = SCREEN_HEIGHT*2;

class CGameGlobal
{
public:
    CGameGlobal()
    : m_width(0)
    , m_height(0)
    , m_resScale(1.0f)
    , m_centerDiffX(0)
    , m_centerDiffY(0)
	, m_logicWidth(1.0f)
	, m_logicHeight(1.0f)
	, m_scaleX(1.0f)
	, m_scaleY(1.0f)
	, m_globalScale(1.0f)
	, m_resolutionScale(1.0f)
    {
    }
    
public:
    static CGameGlobal *GetInstance();

	// 各种坐标，尺寸与屏幕尺寸自适应
	static cocos2d::CCPoint AdjustPos(cocos2d::CCPoint pt);
	static float            AdjustX(float x);
	static float            AdjustY(float y);
	static cocos2d::CCSize  AdjustSize(cocos2d::CCSize s);
	static cocos2d::CCRect  AdjustRect(cocos2d::CCRect rc);

	static cocos2d::CCPoint RestoreLogicPos(cocos2d::CCPoint pt);
	static float            RestoreLogicX(float x);
	static float            RestoreLogicY(float y);

	// 与屏幕分辨率相适应，主要用于IOS高清模式
	static cocos2d::CCPoint AdjustResPos(cocos2d::CCPoint pt);
	static float            AdjustResX(float x);
	static float            AdjustResY(float y);
	static cocos2d::CCSize  AdjustResSize(cocos2d::CCSize s);
	static cocos2d::CCRect  AdjustResRect(cocos2d::CCRect rc);

	static cocos2d::CCPoint RestoreResToLogicPos(cocos2d::CCPoint pt);

	static void AdjustAndroid(cocos2d::CCLayer *pLayer, float scaleAddX = 0, float scaleAddY = 0);
	
    void  InitGlobalData(float logicWidth, float logicHeight, float resScaleFactor, float screenWidth , float screenHeight, bool bRetain);

	void  SetGlobalScale(float scale) {m_globalScale = scale;}
	float GetGlobalScale() {return m_globalScale;}
	
	// 获取将资源尺寸缩放的屏幕实际尺寸所需要的比例
	static float GetScaleX();
	static float GetScaleY();

	static float GetResScaleX();
	static float GetResScaleY();

	static float GetResScale();
	static float GetResolutionScale();

public:
	float m_logicWidth;
	float m_logicHeight;

    float m_width;
    float m_height;
    
    float m_centerDiffX;
    float m_centerDiffY;
    
    float m_resScale;		// 资源图片缩放比例

	float m_scaleX;
	float m_scaleY;

	float m_globalScale;

	float m_resolutionScale;	// 高清模式比例，如果为高清模式，值为2
    
    cocos2d::CCPoint m_ptCenter;

private:
	float m_resScaleX;
	float m_resScaleY;
    
private:
    static CGameGlobal *m_pInstance;
};

#define ccpAdjust(__X__,__Y__) CGameGlobal::AdjustPos(cocos2d::CCPointMake((float)(__X__), (float)(__Y__)))
#define ccpAdjustLogic(__X__,__Y__) CGameGlobal::AdjustPos(cocos2d::CCPointMake((float)(__X__), (float)(__Y__)))
#define ccpAdjustRes(__X__,__Y__) CGameGlobal::AdjustResPos(cocos2d::CCPointMake((float)(__X__), (float)(__Y__)))
#define ccpRestoreRes(__X__,__Y__) CGameGlobal::RestoreResToLogicPos(cocos2d::CCPointMake((float)(__X__), (float)(__Y__)))

#define SCREEN_CENTER CGameGlobal::GetInstance()->m_ptCenter

#endif
